package by.grsu.mikhailava.page.tutor;



import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;

import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;


import by.grsu.mikhailava.app.TestWebApplication;
import by.grsu.mikhailava.dao.SubjectDao;

import by.grsu.mikhailava.entity.Subject;

import by.grsu.mikhailava.page.MyFirstWebPage;


public class SubjectCreatePage extends WebPage{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5806875551578209818L;

	@SuppressWarnings({ "rawtypes", "serial" })
	public SubjectCreatePage(){
		super();
		final Subject subject= new Subject();
		final Form<Subject> form = new Form<Subject>("form",new CompoundPropertyModel<Subject>(subject));
		add(form);

		form.add(new TextField<String>("subjectName"));
		
		form.add(new SubmitLink("create") {
			@Override
			public void onSubmit() {
				super.onSubmit();
				final SubjectDao subjectDao = new SubjectDao(
						TestWebApplication.DATA_XML_FOLDER);
				if (subject.getId() == null) {
					subjectDao.saveNew(subject);
				} else {
					subjectDao.update(subject);
				}
				setResponsePage(TutorSubjectsPage.class);
			}
		});

		form.add(new Link("cancel") {
			@Override
			public void onClick() {
				setResponsePage(MyFirstWebPage.class);
			}
		});
		
		
	
	

}}
